package com.devbobcorn.nekorization.client.event;

import com.devbobcorn.nekorization.Nekorization;
import com.devbobcorn.nekorization.client.model.NekoModel;
import com.devbobcorn.nekorization.client.model.SpriteModel;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.builders.CubeDeformation;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

// Client-Side Only Things...
@EventBusSubscriber(modid = Nekorization.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientModEventSubscriber {
	private static Logger LOGGER = LogManager.getLogger("Client Mod Event Subscriber");

    private static ModelLayerLocation createLocation(String name, String type) {
		return new ModelLayerLocation(new ResourceLocation(Nekorization.MODID, name), type);
	}

	public static final ModelLayerLocation NEKO_TAIL =  createLocation("neko_tail", "main");
	public static final ModelLayerLocation NEKO_INNER = createLocation("neko_inner", "main");
	public static final ModelLayerLocation NEKO_OUTER = createLocation("neko_outer", "main");

	public static final ModelLayerLocation SPRITE = createLocation("sprite", "main");

	@SubscribeEvent
	public static void RegisterLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
		event.registerLayerDefinition(NEKO_TAIL, NekoModel::createTailLayer);
		event.registerLayerDefinition(NEKO_INNER, () -> LayerDefinition.create(HumanoidModel.createMesh(new CubeDeformation(1.02F), 0.0F), 64, 32));
		event.registerLayerDefinition(NEKO_OUTER, () -> LayerDefinition.create(HumanoidModel.createMesh(new CubeDeformation(1.05F), 0.0F), 64, 32));

		event.registerLayerDefinition(SPRITE, SpriteModel::createBodyLayer);

		LOGGER.info("Layer Definitions Registered.");
	}
}
